#include <bits/stdc++.h>
using namespace std;

int a[100020], n, d[100020], ans = 0;

int calc(int n)
{
    int w = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = i - 1; j >= 1; j--)
        {
            if (d[i] == d[j])
            {
                if (a[i] == a[j]) w += a[i];
                break;
            }
        }
    }
    return w;
}

void dfs(int dep, int co)
{
    if (dep > n)
    {
        ans = max(ans, calc(n));
        return ;
    }
    d[dep] = co;

    dfs(dep + 1, 0);
    dfs(dep + 1, 1);
}

int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        cin >> n;
        ans = 0;
        memset(d, 0, sizeof(d));
        for (int j = 1; j <= n; j++)
        {
            cin >> a[j];
        }
        dfs(1, 0);
        dfs(1, 1);
        cout << ans << endl;
    }
    return 0;
}
